package smedi.ismedi.mobile.bff.infrastructure.util;

import com.github.dozermapper.core.DozerConverter;

import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * @Author Jimmy
 * @Date 2021/6/9 13:30
 */
public class DozerLocalDateTimeConverter extends DozerConverter<LocalDateTime, LocalDateTime> {
    public DozerLocalDateTimeConverter() {
        super(LocalDateTime.class, LocalDateTime.class);
    }

    @Override
    public LocalDateTime convertFrom(LocalDateTime source, LocalDateTime destination) {
        if (source == null) return null;
        LocalDateTime dateTime = LocalDateTime.ofInstant(source.atZone(ZoneId.systemDefault()).toInstant(), ZoneId.systemDefault());
        return dateTime;
    }

    @Override
    public LocalDateTime convertTo(LocalDateTime source, LocalDateTime destination) {
        if (source == null) return null;
        LocalDateTime convertToDate = LocalDateTime.from(source.atZone(ZoneId.systemDefault()).toInstant());
        return convertToDate;
    }
}